devang23 Posted December 4, 2009 Share Posted December 4, 2009 So i set up a table in mysql on webhost.com but i cant get this script to work correctly, could it be because i dont have the right "sql="? anyone know what i can do? <html><head><title>Adding a User </title></head> <body> <?php if( (!$firstname) or (!$lastname) or (!$username) or (!$password) ) { $form ="Please enter all new user details"; $form.="<form action=\"$PHP_SELF\""; $form.=" method=\"post\">First Name: "; $form.="<input type=\"text\" name=\firstname\""; $form.=" value=\"$firstname\"><br>Last Name: "; $form.="<input type=\"text\" name=\"lastname\""; $form.=" value=\"$lastname\"><br>UserName: "; $form.="<input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>PassWord: "; $form.="<input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.="<input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo($form); } else { $conn = @mysql_connect("mysql4.000webhost.com") or die("Try Again Punk"); $db = @mysql_select_db("a3213677_snorre", $conn) or die("NOOPE") $sql = "insert into users table(first_name,last_name,user_name,password) values(\"$firstname\",\"$lastname\",\"$username\",password(\$password\") )"; $result = @mysql_query($sql,$conn) or die ("NOT EVEN") if($result) { echo("New User $username ADDED DUH!") ; } } ?> </body></html> EDIT: We got CODE tags. Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/ Share on other sites More sharing options...
Zane Posted December 4, 2009 Share Posted December 4, 2009 define "work correctly". You might find out most of your problems if you take out the error supressors. (The @ symbols) so you can find out why it's not working. In fact, you will Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971606 Share on other sites More sharing options...
devang23 Posted December 4, 2009 Author Share Posted December 4, 2009 did you mean like this <html><head><title>Adding a User </title></head> <body> <?php if( (!$firstname) or (!$lastname) or (!$username) or (!$password) ) { $form ="Please enter all new user details"; $form.="<form action=\"$PHP_SELF\""; $form.=" method=\"post\">First Name: "; $form.="<input type=\"text\" name=\firstname\""; $form.=" value=\"$firstname\"><br>Last Name: "; $form.="<input type=\"text\" name=\"lastname\""; $form.=" value=\"$lastname\"><br>UserName: "; $form.="<input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>PassWord: "; $form.="<input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.="<input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo($form); } else { $conn = ("mysql4.000webhost.com") or die("Try Again Punk"); $db = ("a3213677_snorre",$conn) or die("NOOPE") $sql = "insert into users table(first_name,last_name,user_name,password) values(\"$firstname\",\"$lastname\",\"$username\",password(\$password\") )"; $result = ($sql,$conn) or die ("NOT EVEN") if($result) { echo("New User $username ADDED DUH!") ; } } ?> </body></html> EDIT: Again. we got ...some code... tags.. Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971609 Share on other sites More sharing options...
Zane Posted December 4, 2009 Share Posted December 4, 2009 no... that's not what I meant By doing that you just removed the functions flat out.. which would leave your script doing nothing whatsoever. This is what I meant $conn = @mysql_connect("mysql4.000webhost.com") or die("Try Again Punk"); Also... you can actually find the exact reason something doesn't work if you use the mysql_error function $conn = @mysql_connect("mysql4.000webhost.com") or die("This is your error: -> " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971612 Share on other sites More sharing options...
devang23 Posted December 5, 2009 Author Share Posted December 5, 2009 hang on, the first time i sent it, it had the @s, i dont understand why it wont connect to mysql tables in my database that is set up on third party server Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971658 Share on other sites More sharing options...
Zane Posted December 5, 2009 Share Posted December 5, 2009 hang on, the first time i sent it, it had the @s, i dont understand why it wont connect to mysql tables in my database that is set up on third party server Consider it from this perspective. Imagine that third party server wasn't yours. Better yet, let's assume it is yours still. Now, lets say I use the same script you wrote to connect to your database. Should I be allowed to do this? No. That is why MySQL is set up in such a way that you have to tell the server whom will be connecting to it... and from where they will be connecting. This is the part where you tell us how you manage your third party mysql server so that we can inform you how to ALLOW YOURSELF to connect to it from YOUR "AUTHORIZED" server. Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971673 Share on other sites More sharing options...
devang23 Posted December 5, 2009 Author Share Posted December 5, 2009 hang on, the first time i sent it, it had the @s, i dont understand why it wont connect to mysql tables in my database that is set up on third party server Consider it from this perspective. Imagine that third party server wasn't yours. Better yet, let's assume it is yours still. Now, lets say I use the same script you wrote to connect to your database. Should I be allowed to do this? No. That is why MySQL is set up in such a way that you have to tell the server whom will be connecting to it... and from where they will be connecting. This is the part where you tell us how you manage your third party mysql server so that we can inform you how to ALLOW YOURSELF to connect to it from YOUR "AUTHORIZED" server. okay say i was using a regular mysql, i set up a table called User Table, how would i allow information outside my database to be inserted into my database.... what would i do on mysql that will allow that? Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971676 Share on other sites More sharing options...
Zane Posted December 5, 2009 Share Posted December 5, 2009 This is the part where you tell us how you manage your third party mysql server so that we can inform you how to ALLOW YOURSELF to connect to it from YOUR "AUTHORIZED" server. phpmyadmin, cPanel, mysql console ... ? Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971677 Share on other sites More sharing options...
devang23 Posted December 5, 2009 Author Share Posted December 5, 2009 This is the part where you tell us how you manage your third party mysql server so that we can inform you how to ALLOW YOURSELF to connect to it from YOUR "AUTHORIZED" server. phpmyadmin, cPanel, mysql console ... ? phpmyadmin Quote Link to comment https://forums.phpfreaks.com/topic/184035-dire-need-of-help-newbies-got-problems/#findComment-971678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.