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);


?>
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.