Jump to content

Recommended Posts

Ok so Im trying to make a register function for my website. Im getting frustrated with it, Ive asked my friends to help me, but theyre either busy, or they dont want to help. LOL! (Such nice friends eh?) Heres my coding:

 

<html>
<body>

<form action="registera.php" method="get">
Screen Name: <input type="text" name="sn" />
Password: <input type="text" name="pw" />
<input type="submit" />
</form>

//open connection
$con = mysql_connect("localhost","****","****");
if (!$con)
  {
  die('Could Not Connect: ' . mysql_error());
  }
else
  {
  echo "Connected!";
  }


//select database
mysql_select_db("productions", $con); 


//write to table
$idhigh = mysql_query("SELECT id FROM users ORDER BY desc");
$user = $_GET["sn"];
$pass = $_GET["pw"];
mysql_query("INSERT INTO users ( id, sn, pw)
VALUES ( $idhigh+1, $user, $pass");


//close connection
mysql_close($con);


?>

</body>
</html>

 

I want it to get the username and password from the input boxes and I want it to add 1 more number to the highest id number in the table. Can anyone please help me?

Link to comment
https://forums.phpfreaks.com/topic/56155-writing-to-my-table/
Share on other sites

the function mysql_query() doesn't directly return the resulting data from your query. In any case you don't need to query the database to find the next id. You should set the id column in your table to auto_increment, that means whenever you insert a new record, the next available id will be automatically used for that record without you having to provide any data for that column.

 

You should also read a few tutorials to help you along.

 

http://www.phpfreaks.com/tutorials/142/0.php

Link to comment
https://forums.phpfreaks.com/topic/56155-writing-to-my-table/#findComment-277439
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.