Jump to content

This code is not wroking can anyone help me pls!!!


Sorrow

Recommended Posts

I want to take the info from page 1 send it on page 2 where the only thing that is done in the second page is saving the infos into my database the error is in the query:


<?php
session_start();
$_SESSION['Username'] = $_POST["Username"];


$con = mysql_connect("bla_bla","bla_bla","bla_bla");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("jplegris_pirate", $con);

mysql_query("INSERT INTO Usagers (Username) VALUES ($_SESSION['Username'];)");


mysql_close($con);


?>
[code]
<?php
session_start();
$_SESSION['Username'] = $_POST["Username"];


$con = mysql_connect(host,dbuser,dbpass);
$db = mysql_select_db(dbname,$con);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_query("INSERT INTO Usagers (Username) VALUES ($_SESSION['Username'])");


mysql_close($con);


?>
[/code]
[code]
<?php
session_start();
$_SESSION['Username'] = $_POST['Username'];


$con = mysql_connect(host,dbuser,dbpass);
$db = mysql_select_db(dbname,$con);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_query("INSERT INTO Usagers (Username) VALUES ($_SESSION['Username'])");


mysql_close($con);


?>
[/code]
Alright
[code]
<?php
session_start();
$un = $_POST[Username];
$_SESSION['Username'] = $un;


$con = mysql_connect(host,dbuser,dbpass);
$db = mysql_select_db(dbname,$con);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$sql = "INSERT INTO Usagers (`Username`) VALUES('$un')";
$result = mysql_query($sql);

mysql_close($con);


?>
[/code]

if session username and post username are the same, why not just insert post username into the database?
you cannot use the apostrophes for the variable name between the [ and ] inside quote marks.

so,

<?php
echo "Hello $_POST['Username']"; // will produce an error
echo "Hello $_POST[Username]"; // will succeed
// or better yet
echo 'Hello ' . $_POST['Username'];
?>

so your original code should look like

[code]
<?php
session_start();
$_SESSION['Username'] = $_POST["Username"];

$con = mysql_connect("bla_bla","bla_bla","bla_bla");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("jplegris_pirate", $con);

mysql_query("INSERT INTO Usagers (Username) VALUES (" . $_SESSION['Username'] . ";");

mysql_close($con);
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.