Question

I want to know what is wrong with my code which was the question to Add...

I want to know what is wrong with my code which was the question to Add a form to your php file that has a user put in a Username with the method post. If the name exists in the array, do nothing. If the name does not, add an element to the array with the Username and all other values set to 0. Print out the new array. (PHP)

$array=array(array('username' =>"joeDoe",'tweets'=> 2000,"Followers"=>45,"Following"=>8),

array('username' =>"JohnD", 'tweets'=>62000,"Followers"=>123,"Following"=>160),

array('username' =>"computerSavy",'tweets'=>75,"Followers"=>1,"Following"=>25),

array('username' =>"myTwitterAccount",'tweets'=>1800,"Followers"=>15,"Following"=>6));

echo "

Add New name

";

echo "

" ;

echo "";

echo "

" ;

if (isset($_POST['x']))

{

$new=$_POST['x'];

$check=false;

foreach($array as $key=> $value)

{

if($value['username']==$new )

{

$check=false;

break;

}

if(!$check)

$array=array('username'=>$new, 'tweets'=>0, 'Followers'=>0,'Following'=>0);

}

echo "";

foreach($array as $key =>$value)

{

echo "

";

}

echo"

Handle(Username) Tweets Number of Follwers Following
".$value['username']." ".$value['tweets']." ".$value['Followers']." ".$value["Following"]."

";

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

please check out the code with changes

<?

$array=array(array('username' =>"joeDoe",'tweets'=> 2000,"Followers"=>45,"Following"=>8),

array('username' =>"JohnD", 'tweets'=>62000,"Followers"=>123,"Following"=>160),

array('username' =>"computerSavy",'tweets'=>75,"Followers"=>1,"Following"=>25),

array('username' =>"myTwitterAccount",'tweets'=>1800,"Followers"=>15,"Following"=>6));

echo "Add New name";

echo "

" ;

echo "";

echo "

" ;

if (isset($_POST['x']))

{

$new=$_POST['x'];

$check=false;

foreach($array as $key=> $value)

{

if($value['username']==$new )

{

$check=true;

break;

}

if($check)

$array=array('username'=>$new, 'tweets'=>0, 'Followers'=>0,'Following'=>0);

}

echo "";

foreach($array as $key =>$value)

{

echo "

";

}

echo"

Handle(Username) Tweets Number of Follwers Following

".$value['username']." ".$value['tweets']." ".$value['Followers']." ".$value["Following"]."

";

}

?>

Add a comment
Know the answer?
Add Answer to:
I want to know what is wrong with my code which was the question to Add...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Print out information of PHP use phpinfo() function. 2. Write a program that check and...

    1. Print out information of PHP use phpinfo() function. 2. Write a program that check and print odd / even numbers (from number 1 to 100 using for/while loop). Display the results within an HTML table with 2 columns as shown below: NUMBERS RESULTS 1 ODD 2 EVEN 3 ODD HINT: use <table> tags to create a table, <th> tags for ‘Numbers’ and ‘Results’. Wrap code PHP inside HTML code. For example: ​<html> ​​<title>CHECK ODD or EVEN</title> ​​<body> ​​​<table> ​​​​<?php...

  • PHP - Use of classes This is a further development of the previous task, the participant...

    PHP - Use of classes This is a further development of the previous task, the participant registration. You must use the following Participant class. <?php class Deltaker { private $etterNavn; private $forNavn; private $fAar; function __construct(string $fornavn, string $etternavn, string $aar) { $this->forNavn = $fornavn; $this->etterNavn = $etternavn; $this->fAar = $aar; } function hentEtterNavn() : string { return $this->etterNavn; } function hentForNavn() : string { return $this->forNavn; } function hentFAar() : string{ return $this->fAar; } //Setters function settForNavn(string $fornavn) {...

  • How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow...

    How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...

  • I need help showing the first column of the table to show up exactly with the...

    I need help showing the first column of the table to show up exactly with the mysql table into the php page. Is there a way to fix it ? So I created a php form where the user enters the information. sand.truman.edu/~jyl6557/assignment5/hw5-dataentry.php . it asks for name, hometown, gender(only male and female) and status (freshman, sophmore, junior, senior). once it checks and passes through those tests, it would say added successfully and then show the links to add another...

  • I need help please to add function for clean up any inputs form that we receive from the users for this code below : &lt...

    I need help please to add function for clean up any inputs form that we receive from the users for this code below : <?php session_start(); // initializing variables $fname = ""; $lname = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $email = ""; $phone = ""; $errors = array(); // connect to the database $db = mysqli_connect("localhost","root","password","db"); // REGISTER USER if (isset($_POST['reg_user1'])) { // receive all input values from the form $fname =...

  • For this code below, I need to add the form information to mysql when I click...

    For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS ................................................................................................................................................   <form method="POST"> <div class="container">    <label for="fname"><b>First Name</b></label> <input type="text" placeholder="Enter First Name" name="fname" required> <label for="lname"><b>Last Name</b></label> <input type="text" placeholder="Enter Last Name"...

  • PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head>...

    PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head> <script> </script> </head> <body> <h2>Temperature Conversion Table</h2> <h4>Enter a starting value in degrees Fahrenheit and an increment value.</h4> <form name="myTemp" onsubmit="convertCelcius()" method="post"> <input type="text" name="temperature"> Enter an value in degrees Fahrenheit<br><br> <input type="radio" name="degIncrement" id="degIncrement5"> Convert in increment in 5 degrees<br> <input type="radio" name="degIncrement" id="degIncrement10"> Convert in increment in 10 degrees <br/><br/><input type="submit" value="Submit"> </form> <?php if( $_POST["temperature"] || $_POST["degincrement"] ) { //get he...

  • Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php...

    Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php script, create an associative array named $order that stores the following values: - the number of cheese toppings; - the number of pepperoni toppings; - the number of ham toppings; - the size of the ordered pizza; - the number of the ordered pizza; - the total cost of the order; - the discount rate; - the total cost after the discount. 2) the...

  • PHP Programming In this project, you will create a Web page that allows visitors to your...

    PHP Programming In this project, you will create a Web page that allows visitors to your site to sign a guest book that is saved to a database. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element. Add the following text and elements to the document body: <h2>Enter your name to sign our guest book</h2>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT