Jump to content

chaddsuk

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

chaddsuk's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey guys im having trouble inserting data into my DB, i get the following error.... Parse error: syntax error, unexpected '=' in /home/phphost/public_html/insert.php on line 15 My insert php code is below <? $username="phphost_chadds"; $password="rotherham"; $database="phphost_djdb"; $field1-name = $_POST['name']; $field2-name = $_POST['email']; $field3-name = $_POST['comments']; $field4-name = $_POST['songs']; $field5-name = $_POST['artists']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO dj VALUES ('','$field1-name','$field2-name','$field3-name','$field4-name','$field5-name')" ;mysql_query($query); mysql_close(); ?> Anyone any idea what the problem might be? cheers chris
  2. Hi does anyone have any idea at all how i would be able to change the encoding of a csv file (from unicode - ASCI) using PHP during upload? Is this even possible? ....sorry if i have posted this in the wrong place. Cheers Chris
  3. reall cant get that code working...anyone else any ideas? cheers chris
  4. thanks for that, im not sure where i should place this in my script? ive tried just placing at the top however it just gives me a blank page? could you possibly edit my coe etc to show me what i would need for it to function correctly? thanks again chris
  5. Hi i was wondering how i can alternate the row colors in my table? ive copid and pasted my code below <html><head><title>MySQL Table Viewer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head><body> <?php if (isset($_POST["submit"])) { //DB Variables $user = "root"; // username $pass = "****"; // password $dbname = "test"; // database name $tablename = "users"; // table name mysql_connect ("localhost", $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($dbname); $query = "INSERT INTO $tablename (autoID, name, age, comments, email) VALUES ('0','".$_POST['name']."','".$_POST['age']."','".$_POST['Comments']."','".$_POST['Email']."')"; mysql_query ($query) or die(mysql_error()); // mysql_close ($dbh); You don't really need to close it as it closes automatically once the scripts finished running } ?> <center><form method="POST" action="<?PHP echo $_SERVER["PHP_SELF"]; ?>"> Name:<input type="text" name="name"> Age:<input type="text" name="age"> Comments:<input type="text" name="Comments"> Email:<input type="text" name="Email"> <input type="submit" name="submit" value="submit"> </form> </center> <?php $db_host = 'localhost'; $db_user = 'root'; $db_pwd = '****'; $database = 'test'; $table = 'users'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT name, age, Comments, Email FROM {$table}"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<center><table border='1'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> </body></html> Thanks ahead of time for your help chris
  6. Hi im playing around with adding data to my table, i seem to have it working great now however everytime i refresh the page it re ads the data to the table, whats the best way to stop this from happening? should i make the email addresses unique with mysql?...would that do the trick? cheers chris
  7. Hi im having issues with adding data to my database, as far as i can see everything looks fine but it just isnt working, can someone please take a look at it.... <?PHP if (isset($_POST["submit"])) { //DB Variables $user = "root"; #username $pass = "*****"; #password $dbname = "test"; #database name $tablename = "users"; #table name $dbh=mysql_connect ("localhost", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$dbname"); $query = "INSERT INTO $tablename VALUES ('','$_POST[name]','$_POST[age]','$_POST[Comments]','$_POST')"; #should be one line mysql_db_query ($dbname, $query, $dbh); mysql_close ($dbh); } ?> <form method="POST" action="<?PHP echo $_SERVER["PHP_SELF"]; ?>"> Name:<input type="text" name="name"> Age:<input type="text" name="age"> Comments:<input type="text" name="Comments"> Email:<input type="text" name="Email"> <input type="submit" name="submit" value="submit"> </form> Thanks ahead of time for your help! chris
  8. Ok realised i completely messed up the form, its still wrong but am i getting closer? <center><form action="<?PHP (echo $_SERVER[php_SELF]) mysql_query ("INSERT INTO users (name, age) VALUES ('$name','$age')}"?> method="post"> <input type="text" name="name" size="20" /> Name<br /> <input type="text" name="age" size="20" /> Age<br /> <input type="submit" value="Store in database" /><input type="reset" value="Reset fields" /> </form></center>
  9. Hi Im having trouble inserting data into my database using a html form, can someone take a look at where im am going wrong, i think i have my syntax wrong within my table. copied and pasted below cheers chris <?php //Assign contents of form to variables $name = $_POST['name']; $age = $_POST['age']; ?> <center><form action="<?PHP ($_SERVER[DOCUMENT_SELF]) mysql_query ( "INSERT INTO users (name, age) VALUES ('$name','$age')"; ?>" method="post"> <input type="text" name="name" size="20" /> Name<br /> <input type="text" name="age" size="20" /> Age<br /> <input type="submit" value="Store in database" /><input type="reset" value="Reset fields" /> </form></center>[/color]
  10. Hi im probably going stupidly wrong with this but i cant seem to post data using the form below, the table shows ok and works fine i just cant add data to the table using the form. am i doing something really stupid? thanks chris <?php require "config.php"; ?> <form action="<?php mysql_query("INSERT INTO users (autoID, name)");?>" method="post"> name: <input type="text" name="name" /> <input type="submit" /> </form> <?php // Retrieve all the data from the "example" table $result = mysql_query("SELECT name FROM users") or die(mysql_error()); // store the record of the "example" table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry // just some random data in an array $age = "27"; $data = array('an','example','to','show','the','alternating','row','colors'); $rows = count($data); // the two colors to switch between $rowcolor1 = '#F0F0F2'; $rowcolor2 = '#FFFFFF'; // the background colors on mouseover $hovercolor1 = '#BAD4EB'; $hovercolor2 = '#DCE9F4'; echo ' <center><table style="caption-side: top; border: 0.1em solid #eee; border-collapse: collapse; margin: 1em; width: 30em;"> <caption style="font-weight: bold;">Demonstration of alternate row colors</caption>'; for($n = 0; $n < $rows; $n++) { // this is where the magic happens if($n % 2 == 1) { // add more things to swop with each cycle $style = $rowcolor1; $hoverstyle = $hovercolor1; }else{ $style = $rowcolor2; $hoverstyle = $hovercolor2; } echo ' <tr id="row'.$n.'" style="background:'.$style.';" onmouseover="this.style.background=\''.$hoverstyle.'\'" onmouseout="this.style.background=\''.$style.'\'"> <td style="padding: 0.3em 1em;">'.$row[$n].'</td> </tr>'; } echo ' </table></center>'; ?> Use tags - roopurt18[/b]
  11. Hi i was wondering if anyone had any scripts or any idea on how to display if any other user is viewing the same page as you at the same time... It will be incorporated within a custom built content management system, basically it is meant to stop two people working on the same customer details at the same time while being oblivious to each other. Any idea at all guys on what i could do? cheers chris
  12. hi thanks for that, was being stupid! thanks for your help
  13. Hi im having issues figureing out how the if statement works correctly im using the following... <?php $var = 5; if ($var == 5) ( echo "var was true<br>"; ) ?> ive found that if i remove the curly braces around my echo it works, but if i do that i cant insert code independent of the IF statment? Im using PHP5 btw any help would be appreciated cheers chris
  14. hmm seems to have fixed itself, not sure how though!...thanks for all your help guys, really apreciate it!
×
×
  • 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.