Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP is inserting blanks into MYSQL database! 2

Status
Not open for further replies.

VitoCorleone

Programmer
Jun 22, 2004
28
GB
Hi,

I have the following script that inserts data into my SQL database. its a simple insert query to check if it works! but when i search my database, a new rowhasbeen added but it is blank.

I have looked at my code but cant find anything, can you?

<?php
global $strstaff;
// Database connection variables
$dbServer = "localhost";
$dbDatabase = "dreamhome";
$dbUser = "root";
$dbPass = "harry";

$sConn = mysql_connect($dbServer, $dbUser, $dbPass)
or die("Couldn't connect to database server");
$dConn = mysql_select_db($dbDatabase, $sConn)
or die("Couldn't connect to database $dbDatabase");

$dbQuery = "INSERT INTO staff2 (staff_no) VALUES ";
$dbQuery .= "('$strstaff')";
mysql_query($dbQuery) or die("Couldn't add file to database");

echo "<h1>File Uploaded</h1>"
?>

This is a 2 page insert method. the first page has a simple form which in the form header has

<form enctype="multipart/form-data" name="frmUploadFile" action="grabfile.php" method="post">

and the textbox is called strstaff, hence $strstaff in the PHP code above.

and my database only consists of one column staff_no.
 
If $strstaff is coming from the form, use $_POST['strstaff'] to get the value.

The php.ini variable register_globals is now off by default.

If you had echoed your query before doing the database call, you would have seen the problem.

Ken
 
i changed the query too

$dbQuery = "INSERT INTO staff2 (staff_no) VALUES ";
$dbQuery .= "('$_POST['strstaff']')";
mysql_query($dbQuery) or die("Couldn't add file to database");

Im now getting the error message

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in f:\wamp\ on line 22


and on that line is $dbQuery .= "('$_POST['strstaff']')";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top