December 7, 201114 yr i have error in $query ="insert ..... i don't know what it's extract($_POST); //connect to mysql if (!($dbc=mysql_connect("localhost","root",""))) die("could not connect to database "); //select database $db_selected = mysql_select_db("ehsan",$dbc); if(!$db_selected) { die("cannt connect "); } $query= "INSERT INTO tutorial (code,titile,video) VALUES ('$code','$titile','$video')"; if (! mysql_query($query)) die (mysql_error()); mysql_close(); ?> *********************************************************************************** <form id="form1" name="form1" method="post" action=""> <p> <label for="textfield"></label> <input type="text" name="code" id="textfield" /> code </p> <p> <label for="textfield2"></label> <input type="text" name="titile" id="textfield2" /> title</p> <p> <label for="textfield3"></label> <input type="text" name="video" id="textfield3" /> video</p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form>
December 13, 201114 yr You shouldn't really extract $_POST, its way to insecure. at least add EXTR_PREFIX_ALL: extract($_POST, EXTR_PREFIX_ALL, 'something');
December 13, 201114 yr i have error in $query ="insert ..... i don't know what it's extract($_POST); //connect to mysql if (!($dbc=mysql_connect("localhost","root",""))) die("could not connect to database "); //select database $db_selected = mysql_select_db("ehsan",$dbc); if(!$db_selected) { die("cannt connect "); } $query= "INSERT INTO tutorial (code,titile,video) VALUES ('$code','$titile','$video')"; if (! mysql_query($query)) die (mysql_error()); mysql_close(); ?> *********************************************************************************** <form id="form1" name="form1" method="post" action=""> <p> <label for="textfield"></label> <input type="text" name="code" id="textfield" /> code </p> <p> <label for="textfield2"></label> <input type="text" name="titile" id="textfield2" /> title</p> <p> <label for="textfield3"></label> <input type="text" name="video" id="textfield3" /> video</p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> I think it's because you're trying to insert values you haven't yet posted.. <html> <body> <form id="form1" name="form1" method="post" action=""> <p> <label for="textfield"></label> <input type="text" name="code" id="textfield" /> code </p> <p> <label for="textfield2"></label> <input type="text" name="titile" id="textfield2" /> title</p> <p> <label for="textfield3"></label> <input type="text" name="video" id="textfield3" /> video</p> <p> <input type="submit" name="submit" id="button" value="Submit" /> </p> </form> </body> </html> <?php if($_POST){ extract($_POST); //connect to mysql if (!$dbc=mysql_connect("localhost","root","")) { die("could not connect to database "); } //select database $db_selected = mysql_select_db("test",$dbc); if(!$db_selected) { die("cannt connect "); } $query= "INSERT INTO tutorial (code,titile,video) VALUES ('$code','$titile','$video')"; if (! mysql_query($query)) die (mysql_error()); mysql_close(); } ?> First display the form. Then check if values have been posted. If they have, extract the values and insert into database. if they haven't just display the form. But as someone said, I wouldn't personally use extract().
December 14, 201114 yr Samus, You are right, it is because the values haven't been posted yet, but the solution of putting the form first won't work because they still haven't been posted. ehsan Just set your variables before you try to use them and your original script will work i recon... $code = 0; $title = 0; $video = 0; something like that.
December 14, 201114 yr but the solution of putting the form first won't work because they still haven't been posted. How would you post them without the form then?
December 15, 201114 yr Author Samus, You are right, it is because the values haven't been posted yet, but the solution of putting the form first won't work because they still haven't been posted. ehsan Just set your variables before you try to use them and your original script will work i recon... $code = 0; $title = 0; $video = 0; something like that. MR SAMUS CODE ID RIGTH THANK U MR dddougal To participate Edited December 15, 201114 yr by ehsan_cs
Create an account or sign in to comment