Php not storing in database

Hello,
Below is the script there are no errors but php is not storing inputted data to mysql.
[php]

Step 1

Please enter the specified information

Number of Items :
Name of Raffle :
Slots :
Credit :
SteamID of user :
SteamID of Admin:

<? if($_POST) { $no = $_POST['no']; setcookie("no", $no, time()+120); $nameofraffle = $_POST['nameofraffle']; $slots = $_POST['slots']; $credits = $_POST['credits']; $usteamid =$_POST['usteamid']; $asteamid =$_POST['asteamid']; $otherinfo =$_POST['otherinfo'];

$host = ‘localhost’;
$pass = ‘’;
$user = ‘root’;
$db = ‘test’;
$con=mysqli_connect($host,$user,$pass,$db);

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,“INSERT INTO tstraffle VALUES (’$nameofraffle’,’$slots’,’$otherinfo’,’$credits’,’$usteamid’,’$asteamid’”);

$RID =mysqli_query($con,"SELECT * FROM tstraffle ORDER BY RID DESC LIMIT 1");
setcookie("rid", $RID, time()+120);

if(mysqli_affected_rows($con) >=1)
{
$host = $_SERVER[‘HTTP_HOST’];
$uri = rtrim(dirname($_SERVER[‘PHP_SELF’]), ‘/\’);
$extra = ‘step1.php’;
header(“Location: http://$host$uri/$extra”);
exit;
}
else{
echo ‘did you miss something??? cause its not done…’;
}
mysqli_close($con);
}
?>

[/php]
And this
[php]<?php
/**

  • Created by PhpStorm.

  • User: karan

  • Date: 13/03/14

  • Time: 10:06 AM
    */
    $rid = $_COOKIE[‘rid’];
    $no = $_COOKIE[‘no’];
    if ($_POST)
    {
    $db = new PDO(“mysql:host=localhost;dbname=test”, “root”, “”);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $insertStmt = $db->prepare(“INSERT INTO items (raffle_id,item,item_info) VALUES (’.$rid.’,?,?)”);

    for ($i = 0; $i < count($_POST[‘field1’]); $i++)
    {
    $insertStmt->execute(array(
    $_POST[‘item’][$i],
    $_POST[‘q’][$i]
    ));
    }

if(mysqli_affected_rows($con) >=1)
{
echo ‘Done,Please check the raffle page.’;
}
else{
echo ‘did you miss something??? cause its not done…
or CONTACT FROST ALMIGHTY’;
}
}

?>

<? for ($x = 0; $x <= $no; $x++) { echo "Item $x:
\n"; echo "Quality$x :
\n"; }

?>[/php]
Thanks

& i tried storing RID and NO in Session which didnt seem to work so i stored them in cookies
Thanks

I help you as much as I can:
I don’t see how you’re not get any errors if no data is being stored? Unless you don’t have your MySQL database setup correctly, might want to check into that?
You should turn on error checking:
[php]ini_set(‘display_errors’,1);
error_reporting(E_ALL);[/php]

I’m assuming raffle_id is generate in php, rather than auto_increment in mysql database; however, most of the time it is auto incremented in MySQL.

[php]if (isset($_POST[‘submit’]) && $_POST[‘submit’] == ‘enter’)
{
$db = new PDO(“mysql:host=localhost;dbname=test”, “root”, “”);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query = "INSERT INTO items (raffle_id,item,item_info) VALUES (:raffle_id, :item, :item_info)";
$insertStmt = $db->prepare($query);
$result = $insertStmt->execute(array(':raffle_id' => $_POST['raffle_id'], ':item' => $_POST['item'], 'item_info' => $_POST['item_info']))

}[/php]

I can’t help you with the rest of your script’s logic and you will most like have to re-write the above php script (I’m 99 percent sure of that).

I also know in your form (unless you’re using some kind of JavaScript) that your submit button is wrong for you’re missing name=“submit” where in between the quotes can be anything:

[php][/php]

I hope this at least steers you in the right direction.

Sponsor our Newsletter | Privacy Policy | Terms of Service